<template>
  <div id="community">
    <el-table :data="detail.list" style="width: 100%" border>
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column prop="id" label="时间段编号" width="120" align="center"/>
      <el-table-column prop="timename" label="时间段名称" align="center"/>
      <el-table-column prop="begtime" label="开始时间" align="center"/>
      <el-table-column prop="endtime" label="结束时间" align="center"/>
      <el-table-column align="center">
        <template #header>
          操作
        </template>
        <template #default="scope">

          <el-button @click="handleEdit(scope.$index)" type="primary" plain>
            编辑
          </el-button>

          <el-button type="danger" @click="handleDelete(scope.$index)">
            删除
          </el-button>

          <!-- 修改信息 -->
          <el-dialog v-model="dialogFormVisible" title="修改信息" :modal="modal">
            <UpdateShiJian :current="current"></UpdateShiJian>
          </el-dialog>

        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import UpdateShiJian from "../manager/UpdateShiJian.vue";

import axios from "axios";
import qs from "querystring";
export default {
  name: "ShiJianDuanVue",
  data() {
    return {
      detail: [
        {
          list: [{}],
        },
      ],
      current: {},
      dialogFormVisible: false,
      modal: false,
    };
  },
  methods: {
    handleEdit(index) {
      this.current = this.detail.list[index];
      this.dialogFormVisible = true;
    },
    handleDelete(index) {
      console.log(this.detail[index]);
      axios
        .post(
          "http://localhost:8080/library/deleteSH",
          qs.stringify(this.detail.list[index]),
          {
            headers: {
              "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
            },
          }
        )
        .then((res) => {
          console.log(res.data.code);
          if (res.data.code == 1) {
            console.log("删除成功");
          } else {
            console.log("error");
          }
        });
    },
    mount() {
      axios
        .post(
          "http://localhost:8080/library/shiJianDuanFindAll",
          qs.stringify(this.list),
          {
            headers: {
              "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
            },
          }
        )
        .then((res) => {
          console.log(res.data);
          if (res.data.code == 1) {
            this.detail.list = res.data.data;
          } else {
            console.log("error");
          }
        });
    },
  },
  mounted() {
    this.mount();
  },
  components: { UpdateShiJian },
};
</script>

<style scoped>
</style>